
cmake_minimum_required(VERSION 3.15)

project(all_in_one CXX)

foreach (dirname ${CMAKE_CURRENT_SOURCE_DIR})
    file(GLOB_RECURSE AO_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
            "${dirname}/*.h"
            "${dirname}/*.hpp"
            "${dirname}/*.c"
            "${dirname}/*.cpp"
    )

endforeach ()

# set(AO_STATIC_LIB 1)
if (AO_SHARE_LIB)
    message("构建动态库")
    add_library(${PROJECT_NAME} SHARED ${AO_SRC_FILES})
else ()
    message("构建静态库")
    add_library(${PROJECT_NAME} STATIC ${AO_SRC_FILES})
endif ()

# json
find_package(jsoncpp CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC JsonCpp::JsonCpp)

# zlib
find_package(ZLIB REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC ZLIB::ZLIB)

# iconv
find_package(Iconv)
target_link_libraries(${PROJECT_NAME} PUBLIC Iconv::Iconv)

# gdal
if (ENABLE_GDAL)
    message("启用 gdal")
    find_package(GDAL CONFIG REQUIRED)
    target_link_libraries(${PROJECT_NAME} PUBLIC GDAL::GDAL)
    add_definitions(-DENABLE_GDAL)
endif ()

# mqtt
if (ENABLE_PAHO_MQTT)
    message("启用 paho mqtt")
    find_package(PahoMqttCpp CONFIG REQUIRED)
    if (IS_LINUX)
        target_link_libraries(${PROJECT_NAME} PUBLIC PahoMqttCpp::paho-mqttpp3-static)
    else ()
        target_link_libraries(${PROJECT_NAME} PUBLIC PahoMqttCpp::paho-mqttpp3)
    endif ()
    add_definitions(-DENABLE_PAHO_MQTT)
endif ()

# spdlog日志
find_package(spdlog CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC spdlog::spdlog
        spdlog::spdlog_header_only)
# png
find_package(PNG REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC PNG::PNG)

find_package(PkgConfig REQUIRED)
pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0)
target_link_libraries(${PROJECT_NAME} PUBLIC PkgConfig::libusb)

# asio: socket
if (ENABLE_ASIO_SOCKET)
    MESSAGE("启用 asio socket")
    find_package(asio CONFIG REQUIRED)
    target_link_libraries(${PROJECT_NAME} PUBLIC asio::asio)
    add_definitions(-DENABLE_ASIO_SOCKET)
endif ()


if (IS_LINUX)

endif ()